<template>
    <base-dialog  v-bind="$attrs"
                  v-on="$listeners" size="tinylong" :no-button="true">
        <el-table
                :data="dataList"
                class="full-width"
                row-key="id"
                height="600px"
        >
            <el-table-column align="left" type="index" label="序号" width="60">
                <template slot-scope="scope">
                    {{scope.$index+1}}
                </template>
            </el-table-column>
            <el-table-column align="left" prop="name" label="名称"/>
            <el-table-column align="left" label="操作" v-if="showSelection">
                <template slot-scope="{row}">
                    <my-button @click="addGroup(row)" handle="Retrieve">加入</my-button>
                </template>
            </el-table-column>
            <el-table-column align="left" label="操作" v-else>
                <template slot-scope="{row}">
                    <my-button @click="deleteGroup(row)" handle="Retrieve">删除</my-button>
                </template>
            </el-table-column>
        </el-table>
    </base-dialog>
</template>
<script>
    import BaseDialog from "../../components/Common/BaseDialog";
    import api from "@/api/addressBook/group/index";
    export default {
        name:"GroupListDialog",
        components: {BaseDialog},
        props:["dataList","showSelection","disabled","userRow"],
        data(){
            return{
                multipleSelection:[],
                roleUser: {user:this.userRow.id,group:undefined},
                currRow:{}
            }
        },
        methods:{
            addGroup(row){
                this.roleUser.group = row.id
                this.$confirm("加入群组, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                   api.bookaddressGroupsAdd(this.roleUser)
                        .then(res => {
                            this.msgSuccess("添加成功!");
                        });
                });
            },
            deleteGroup(row){
                this.roleUser.group = row.id
                this.$confirm("删除群组, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    api.bookaddressGroupsDelete(this.roleUser)
                        .then(res => {
                            this.msgSuccess("添加成功!");
                        });
                });
            },
            toAdd(){

            },
        }
    }
</script>
